<?php $this->_extends('_layouts/default_layout'); ?>
 
<?php $this->_block('contents'); ?>


<span><a href="<?php echo url('departments/index'); ?>">部门管理</a> &nbsp;&nbsp;&nbsp;添加用户到 <?php echo $dep->department_name; ?>部</span>

<form action="<?php echo url('departments/addmember'); ?>" method="post" name="mainform" enctype="multipart/form-data" >
	<table cellpadding="0" cellspacing="0" width="100%">
	<tbody class="">
		<tr class="tth">
		<td width="10%">选择</td>
		<td width="20%">用户名</td>
		<td width="30%">用户实名</td>
		<td width="*">用户部门</td>
		</tr>
 	<?php foreach ($users as $user): ?>		
       <tr>
			<td><input type="checkbox" name="checkboxid[]"  id="checkboxid" value="<?php echo $user->id() ?>" /></td>
			<td><?php echo $user->username ?></td>
			<td><?php echo $user->user_realname ?></td>
            <td><?php $deps=$user->getDepartmentInfo(); 
                    if($deps == null) 
                    {
                        echo "默认部门"; 
                    }
                    else
                    {
                        echo $deps->department_name;
                    }
                ?>
             </td>
		</tr>
	<?php endforeach; ?>	
    <input type="hidden" name="department_id" id="department_id" value="<?php echo $dep->department_id ?>" />

	</tbody>
	<tr>
		<td class="tbutton" colspan="6"><input type="button" value="全选" class="btn" name="choseall" id="Name" onclick="SelectAll()">&nbsp;<input type="submit" onClick="return(CheckFirst())" value="添加" class="btn" name="submit"></td>
	</tr>
	</table>
</form>
<?php $this->_control('pagination', 'my-pagination', array('url_args' => array('department_id' => $dep->id()), 'pagination' => $pagination)); ?>

<script>
	function SelectAll() {
	 var flg=0;
	 var checkboxs=document.getElementsByName("checkboxid[]");
	 var count=0;
	 for (var j=0; j<checkboxs.length; j++)
	 {
		var e=checkboxs[j];
		if(e.checked)count++;
	 }
	 if(count < checkboxs.length)
	 {
		 for (var i=0;i<checkboxs.length;i++) {
			 var e=checkboxs[i];
			 e.checked =1;
			 flg= true;
		 }
	 }
	 else 
	 {
		 for (var i=0;i<checkboxs.length;i++) {
			 var e=checkboxs[i];
			 e.checked =0;
			 flg= false;
		 }

	 }

	 if (flg)
	 {
		document.mainform.choseall.value = "取消";
	 }
	 else
	 {
		document.mainform.choseall.value = "全选";
	 }

	}

	function CheckFirst()
	{
	    var count=0;
        var checkboxs=document.getElementsByName("checkboxid[]");
	    for (var i=0;i<checkboxs.length;i++)
		{
		    var e=checkboxs[i];
		    if(e.checked)count++;
	    }
        if(count == 0)
		{
			alert('请先选择添加条目'); 
			return false;
		}
		else
		{
			alert('您确认要添加吗'); 	
			return true;		
		}
	}
</script>

<?php $this->_endblock(); ?>
